<template>
  <div class="app-container">
    <el-form class="top" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入商店名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="storeType">
        <el-select v-model="queryParams.storeType" placeholder="请选择商店类型" clearable>
          <el-option
            v-for="dict in dict.type.scenery_store_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="主要商品" prop="storeMain">
        <el-input
          v-model="queryParams.storeMain"
          placeholder="请输入商店主要商品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评分" prop="storeScore">
        <el-select v-model="queryParams.storeScore" placeholder="请选择商店评分" clearable>
          <el-option
            v-for="dict in dict.type.scenery_score"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="人均价格" prop="storePrice">
        <el-input
          v-model="queryParams.storePrice"
          placeholder="请输入商店人均价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排队时间" prop="storeWaitTime">
        <el-input
          v-model="queryParams.storeWaitTime"
          placeholder="请输入商店排队时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="摄像头id" prop="storeCameraId">
        <el-input
          v-model="queryParams.storeCameraId"
          placeholder="请输入摄像头id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="摄像状态" prop="storeCameraState">
        <el-select v-model="queryParams.storeCameraState" placeholder="请选择摄像头当前状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_notice_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商店日入" prop="storeIncomeDay">
        <el-input
          v-model="queryParams.storeIncomeDay"
          placeholder="请输入商店日入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商店月入" prop="storeIncomeMonth">
        <el-input
          v-model="queryParams.storeIncomeMonth"
          placeholder="请输入商店月入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商店年入" prop="storeIncomeYear">
        <el-input
          v-model="queryParams.storeIncomeYear"
          placeholder="请输入商店年入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['scenery:store:add']"
        >新增</el-button>
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['scenery:store:edit']"-->
<!--        >修改</el-button>-->
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['scenery:store:remove']"
        >删除</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['scenery:store:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
    <el-col :span="6" class="card-box" v-for="item in this.storeList" :class="isFlipped ? 'flipped' : ''">
      <transition name="flip">
        <el-card class="card-front" v-if="!isFlipped" key="front" :style="{backgroundImage: 'url(' + item.storeImage + ')'}">
          <div class="card-header">
            <div class="card-name">
              <span>ID:</span>{{item.storeId}}
              <span class="card-type">{{dict.type.scenery_store_type[item.storeType].label }}</span>
            </div>
            <h3 class="card-title">{{item.storeName}}</h3>
          </div>
          <div class="card-middle">
            <div class="card-middle1">
              <img class="card-symbol" src="./money1.png">
              <span class="card-count">{{item.storePrice}}</span>
            </div>
            <div class="card-middle2">
              <img class="card-symbol" src="./time1.png">
              <span class="card-count">{{item.storeWaitTime}}</span>
              <span class="card-symbol">min</span>
            </div>
          </div>
          <div class="card-bottom">
            <img class="card-symbol" src="./star11.png" v-for="item in (5-item.storeScore)">
          </div>
          <div>
            <el-button
              class="card-button-edit"
              size="mini"
              @click="handleUpdate(item)"
              v-hasPermi="['store:data:edit']"
            >修改</el-button>
            <el-button
              class="card-button-delete"
              size="mini"
              @click="handleDelete(item)"
              v-hasPermi="['store:data:remove']"
            >删除</el-button>
            <el-button
              class="card-button-flip"
              size="mini"
              @click="flipCard"
            >具体信息</el-button>
            <div class="card-label">
              <span class="card-text">{{item.storeMain}}</span>
            </div>
          </div>
        </el-card>
        <el-card class="card-back" v-else key="back" :style="{backgroundImage: 'url(' + item.storeImage + ')'}">
          <div class="card-header">
            <div class="card-name">
              <span>摄像头</span>{{item.storeCameraId}}
              <span class="card-state">{{dict.type.sys_notice_status[item.storeCameraState].label}}</span>
            </div>
            <h3 class="card-title">商店营收情况</h3>
            <div class="card-info">日入：¥ {{item.storeIncomeDay}}</div>
            <div class="card-info">月入：¥ {{item.storeIncomeMonth}}</div>
            <div class="card-info">年入：¥ {{item.storeIncomeYear}}</div>
          </div>
          <div class="card-bottom">
            <el-button
              class="card-button-flip"
              size="mini"
              @click="flipCard"
            >返回</el-button>
          </div>
        </el-card>
      </transition>
    </el-col>
    <!--    为了让分页的那个条下去，不要错位-->
    <div style="clear: both;"></div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商店管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入商店名称" />
        </el-form-item>
        <el-form-item label="类型" prop="storeType">
          <el-select v-model="form.storeType" placeholder="请选择商店类型">
            <el-option
              v-for="dict in dict.type.scenery_store_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主要商品" prop="storeMain">
          <el-input v-model="form.storeMain" placeholder="请输入商店主要商品" />
        </el-form-item>
        <el-form-item label="评分" prop="storeScore">
          <el-select v-model="form.storeScore" placeholder="请选择商店评分">
            <el-option
              v-for="dict in dict.type.scenery_score"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人均价格" prop="storePrice">
          <el-input v-model="form.storePrice" placeholder="请输入商店人均价格" />
        </el-form-item>
        <el-form-item label="排队时间" prop="storeWaitTime">
          <el-input v-model="form.storeWaitTime" placeholder="请输入商店排队时间" />
        </el-form-item>
        <el-form-item label="摄像头id" prop="storeCameraId">
          <el-input v-model="form.storeCameraId" placeholder="请输入商店摄像头id" />
        </el-form-item>
        <el-form-item label="摄像头状态" prop="storeCameraState">
          <el-select v-model="form.storeCameraState" placeholder="请选择摄像头当前状态">
            <el-option
              v-for="dict in dict.type.sys_notice_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商店日入" prop="storeIncomeDay">
          <el-input v-model="form.storeIncomeDay" placeholder="请输入商店日入" />
        </el-form-item>
        <el-form-item label="商店月入" prop="storeIncomeMonth">
          <el-input v-model="form.storeIncomeMonth" placeholder="请输入商店月入" />
        </el-form-item>
        <el-form-item label="商店年入" prop="storeIncomeYear">
          <el-input v-model="form.storeIncomeYear" placeholder="请输入商店年入" />
        </el-form-item>
        <el-form-item label="商店图片" prop="storeImage">
          <image-upload v-model="form.storeImage"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStore, getStore, delStore, addStore, updateStore } from "@/api/scenery/store";
import {background} from "quill/ui/icons";

export default {
  name: "Store",
  dicts: ['sys_notice_status', 'scenery_store_type', 'scenery_score'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 是否翻转
      isFlipped: false,
      // 总条数
      total: 0,
      // 商店管理表格数据
      storeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        storeName: null,
        storeType: null,
        storeMain: null,
        storeScore: null,
        storePrice: null,
        storeWaitTime: null,
        storeCameraId: null,
        storeCameraState: null,
        storeIncomeDay: null,
        storeIncomeMonth: null,
        storeIncomeYear: null,
        storeImage: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    background,
    /** 查询商店管理列表 */
    getList() {
      this.loading = true;
      listStore(this.queryParams).then(response => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        storeId: null,
        storeName: null,
        storeType: null,
        storeMain: null,
        storeScore: null,
        storePrice: null,
        storeWaitTime: null,
        storeCameraId: null,
        storeCameraState: null,
        storeIncomeDay: null,
        storeIncomeMonth: null,
        storeIncomeYear: null,
        storeImage: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.storeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商店管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const storeId = row.storeId || this.ids
      getStore(storeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商店管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.storeId != null) {
            updateStore(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStore(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const storeIds = row.storeId || this.ids;
      this.$modal.confirm('是否确认删除商店管理编号为"' + storeIds + '"的数据项？').then(function() {
        return delStore(storeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('scenery/store/export', {
        ...this.queryParams
      }, `store_${new Date().getTime()}.xlsx`)
    },
    /** 翻转卡片操作 */
    flipCard() {
      this.isFlipped = !this.isFlipped;
    }
  }
};
</script>
